package com.eazytec.common.util.file.office;

import java.io.IOException;
import java.util.Map;
import com.eazytec.common.util.ConstWords;
import freemarker.template.TemplateException;

public class ExportWord {
	
	private static String realPath;
	
	public static void setRealPath(String path) throws NumberFormatException, IOException{
		realPath = path + ConstWords.DOWNLOADFILE_PATH;
	}
	
	//定义导出WORD文件的名称，使用英文名称，中文名称不兼容
	public static final String ANNOUNCE_FILE_NAME = "gonggao.doc";//名称
	public static final String ANNOUNCE_TEMPLATE = "gonggao.xml";//模板
	
	
	/**
	 * 导出公告word
	 * @param path
	 * @param map
	 * @throws TemplateException 
	 * @throws IOException 
	 */
	public static String exportAnnounce(Map<String, Object> map) throws IOException, TemplateException {
		String fileName = realPath + ANNOUNCE_FILE_NAME;
		getDocumentHandler().exportWord(fileName, map, ANNOUNCE_TEMPLATE);
		return fileName;
	}
	
	/**
	 * 获得DocumentHandler
	 * @return
	 * @throws IOException
	 */
	private static DocumentHandler getDocumentHandler() throws IOException{
		return new DocumentHandler();
	}
}
